<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>增删改查</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>


</head>
<body>
<div class="btn-group col-md-12 " role="group" aria-label="...">
    <button type="button" class="col-md-1 btn btn-success" id="insert">插入数据</button>
    <input type="text" class="insertData" placeholder="请输入age" id="addAge">
    <input type="text" class="insertData" placeholder="请输入name" id="addName">
</div>
<div class="btn-group col-md-12 " role="group" aria-label="...">
    <button type="button" class="col-md-1 btn btn-success">修改数据</button>
    <input type="text" class="insertData" placeholder="请输入ID">
    <input type="text" class="insertData" placeholder="请输入age">
    <input type="text" class="insertData" placeholder="请输入name">
</div>
<div class="btn-group col-md-12 " role="group" aria-label="...">
    <button type="button" id="delete" class="col-md-offset-1 col-md-1 btn btn-danger">删除</button>
    <input type="text" class="deleteData" placeholder="请输入ID" id="deleteValue">
</div>
<div class="btn-group col-md-12" role="group" aria-label="...">
    <button type="button" id="select" class="col-md-offset-1 col-md-1 btn btn-info">查询数据</button>
</div>
</body>
<script>
    $(function (){
        //查找
        $("#select").click(function(){
            $.ajax({
                url:"/user/queryAll",
                type: "get",
                success:function (data) {
                    console.log(data);
                }
            })
        })
        //删除
        $("#delete").click(function(){
            var id = $("#deleteValue").val();
            console.log(id);
            $.ajax({
                url:"/user/delete",
                type: "post",
                data:{
                    id:id
                },
                success:function (data) {
                    $("#deleteValue").empty();
                    window.location.reload();
                    console.log(data);
                }
            })
        })

        //插入
        $("#insert").click(function (){
            var age = $("#addAge").val();
            var name = $("#addName").val();
            $.ajax({
                url:"/user/save",
                type:"post",
                data: {
                    name:name,
                    age:age
                },
                success:function (data){
                    console.log(data);
                }
            })
        })



    })
</script>
</html>